import pandas as pd


def read_csv(f_path:str):
    return pd.read_csv(f_path, encoding='utf-8', index_col=0)


def display_data_info(data:pd.DataFrame):
    print(data.head(10))
    print(data.columns)
    print(data.dtypes)
    pass


def drop_row(data:pd.DataFrame, row_name):
    # 删除行
    data.drop(row_name, axis=0, inplace=True)


def drop_column(data:pd.DataFrame, column_name):
    # 删除列
    data.drop(column_name, axis=1, inplace=True)


def drop_column_by_dataframe(data_A:pd.DataFrame, data_B:pd.DataFrame):
    if set(data_B.columns) == set(data_A.columns):
        return data_A[~data_A.isin(data_B).all(axis=1)]
    else:
        return data_A


def merge_dataframe(baseData, newData, update=False):
    """

    :param baseData: 基础数据
    :param newData:  更新的数据
    :param update: 如果列相同可以直接更新，不同会给merge的部分赋值nan
    :return:
    """
    if update:
        baseData.update(newData)
    else:
        baseData.combine_first(newData)

    return baseData

# union(并)、 except(差)、intersect(交)


def get_break(df: pd.DataFrame):
    # removing all empty dates
    # build complete timeline from start date to end date
    dt_all = pd.date_range(start=df.index[0], end=df.index[-1])
    # retrieve the dates that ARE in the original datset
    dt_obs = [d.strftime("%Y-%m-%d") for d in pd.to_datetime(df.index)]
    # define dates with missing values
    dt_breaks = [d for d in dt_all.strftime("%Y-%m-%d").tolist() if not d in dt_obs]

    return dt_breaks


class WithIndex():
    pass


class WithoutIndex():
    pass

